var MaxQueue = function () {
  this.queue = [] // 创建一个队列
  this.maxValues = []
};

/**
 * @return {number}
 */
MaxQueue.prototype.max_value = function () {
  if (this.queue.length === 0) {
    return -1
  }
 return this.maxValues[0]
};

/** 
 * @param {number} value
 * @return {void}
 */
MaxQueue.prototype.push_back = function (value) {
  this.queue.push(value) // 在队尾添加元素
  // 从后往前遍历最大值数组,将小于新元素的值都删除
  while (this.maxValues.length > 0 && this.maxValues[this.maxValues.length - 1] < value) {
    this.maxValues.pop()
  }
  this.maxValues.push(value)
};

/**
 * @return {number}
 */
MaxQueue.prototype.pop_front = function () {
  if (this.queue.length == 0) {
    return -1
  }
  let front = this.queue.shift()
  if (front === this.maxValues[0]) {
    this.maxValues.shift()
  }
  return front
};

/**
 * Your MaxQueue object will be instantiated and called as such:
 * var obj = new MaxQueue()
 * var param_1 = obj.max_value()
 * obj.push_back(value)
 * var param_3 = obj.pop_front()
 */